home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / LiveFastStartServer / Open Transport 1.3 / Includes / CIncludes / OpenTptInternet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-30  |  10.2 KB  |  378 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OpenTptInternet.h
  3.  
  4.     Contains:    Client TCP/IP definitions
  5.  
  6.     Copyright:    © 1993-1997 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. */
  10.  
  11.  
  12. #ifndef __OPENTPTINTERNET__
  13. #define __OPENTPTINTERNET__
  14.  
  15. #ifndef __OPENTRANSPORT__
  16. #include <OpenTransport.h>
  17. #endif    
  18. #if PRAGMA_ALIGN_SUPPORTED
  19. #pragma options align=mac68k
  20. #endif
  21. #if PRAGMA_IMPORT_SUPPORTED
  22. #pragma import on
  23. #endif
  24.  
  25. /*******************************************************************************
  26. ** Misc 
  27. ********************************************************************************/
  28.  
  29. typedef UInt16    InetPort;
  30. typedef UInt32    InetHost;
  31.  
  32. //
  33. //    Enums used as address type designations.
  34. //
  35. enum
  36. {
  37.     AF_INET                = 2,    // Traditonal
  38.     AF_DNS                = 42    // Obviously, the answer to...
  39. };
  40.  
  41. //
  42. //    Enum which can be used to bind to all IP interfaces
  43. //    rather than a specific one.
  44. //
  45. enum
  46. {
  47.     kOTAnyInetAddress    = 0        // Wildcard
  48. };
  49.  
  50. #ifdef __cplusplus
  51.     class    TInternetServices;
  52.     typedef TInternetServices*    InetSvcRef;
  53. #else
  54.     typedef void*    InetSvcRef;
  55. #endif
  56.  
  57. /*******************************************************************************
  58. ** Some prefixes for shared libraries
  59. ********************************************************************************/
  60.  
  61. #define kInetVersion    "3.1.1"
  62. #define kInetPrefix        "ot:inet$"
  63.  
  64. /*******************************************************************************
  65. ** Module Names
  66. ********************************************************************************/
  67. #define kDNRName        "dnr"
  68. #define kTCPName        "tcp"
  69. #define kUDPName        "udp"
  70. #define kRawIPName        "rawip"
  71.  
  72. /*******************************************************************************
  73. ** XTI Options
  74. ********************************************************************************/
  75.  
  76. // Protocol levels
  77.  
  78. #define    INET_IP         0x0
  79. #define    INET_TCP     0x06
  80. #define    INET_UDP     0x11
  81.  
  82.  
  83. // TCP Level Options
  84.  
  85. #define    TCP_NODELAY                     0x01
  86. #define    TCP_MAXSEG                     0x02
  87. #define TCP_NOTIFY_THRESHOLD        0x10    /** not a real XTI option */
  88. #define TCP_ABORT_THRESHOLD            0x11    /** not a real XTI option */
  89. #define TCP_CONN_NOTIFY_THRESHOLD    0x12    /** not a real XTI option */
  90. #define TCP_CONN_ABORT_THRESHOLD    0x13    /** not a real XTI option */
  91. #define TCP_OOBINLINE                0x14    /** not a real XTI option */
  92. #define TCP_URGENT_PTR_TYPE            0x15    /** not a real XTI option */
  93. #define    TCP_KEEPALIVE                 OPT_KEEPALIVE    /* keepalive defined in OpenTransport.h */
  94.  
  95. #define    T_GARBAGE                     2            
  96.  
  97.  
  98. // UDP Level Options
  99.  
  100. #define    UDP_CHECKSUM        OPT_CHECKSUM
  101. #define UDP_RX_ICMP            0x2
  102.  
  103. // IP Level Options
  104.  
  105. #define    IP_OPTIONS             0x01
  106. #define    IP_TOS                 0x02
  107. #define    IP_TTL                 0x03
  108. #define    IP_REUSEADDR         0x04
  109. #define    IP_DONTROUTE         0x10
  110. #define    IP_BROADCAST         0x20
  111. #define    IP_HDRINCL             0x1002    
  112. #define IP_RCVOPTS             0x1005
  113. #define IP_RCVDSTADDR         0x1007
  114. #define    IP_MULTICAST_IF         0x1010        /* set/get IP multicast interface    */
  115. #define    IP_MULTICAST_TTL     0x1011        /* set/get IP multicast timetolive    */
  116. #define    IP_MULTICAST_LOOP     0x1012        /* set/get IP multicast loopback    */
  117. #define    IP_ADD_MEMBERSHIP     0x1013        /* add an IP group membership        */
  118. #define    IP_DROP_MEMBERSHIP     0x1014        /* drop an IP group membership        */
  119. #define    IP_BROADCAST_IF         0x1015        /* Set interface for broadcasts     */
  120. #define    IP_RCVIFADDR         0x1016        /* Set interface for broadcasts     */
  121.  
  122. //    DVMRP-specific setsockopt commands, from ip_mroute.h
  123. //
  124. #define    DVMRP_INIT        100
  125. #define    DVMRP_DONE        101
  126. #define    DVMRP_ADD_VIF    102
  127. #define    DVMRP_DEL_VIF    103
  128. #define    DVMRP_ADD_LGRP    104
  129. #define    DVMRP_DEL_LGRP    105
  130. #define    DVMRP_ADD_MRT    106
  131. #define    DVMRP_DEL_MRT    107
  132.  
  133. // IP_TOS precdence levels
  134. enum
  135. {
  136.     T_ROUTINE        = 0,
  137.     T_PRIORITY        = 1,
  138.     T_IMMEDIATE        = 2,
  139.     T_FLASH            = 3,
  140.     T_OVERRIDEFLASH    = 4,
  141.     T_CRITIC_ECP    = 5,
  142.     T_INETCONTROL    = 6,
  143.     T_NETCONTROL    = 7
  144. };
  145.  
  146. //    IP_TOS type of service
  147. enum
  148. {
  149.     T_NOTOS        = 0x0,        
  150.     T_LDELAY    = (1<<4),
  151.     T_HITHRPT    = (1<<3),
  152.     T_HIREL     = (1<<2)
  153. };
  154.  
  155. #define    SET_TOS(prec,tos)    (((0x7 & (prec)) << 5) | (0x1c & (tos)))
  156.  
  157. // IP Multicast option structures
  158. struct TIPAddMulticast
  159. {
  160.     InetHost multicastGroupAddress;
  161.     InetHost interfaceAddress;
  162. };
  163. typedef struct TIPAddMulticast TIPAddMulticast;
  164.  
  165.  
  166. /*******************************************************************************
  167. ** Protocol-specific events
  168. ********************************************************************************/
  169.  
  170. enum
  171. {
  172.     T_DNRSTRINGTOADDRCOMPLETE    = kPRIVATEEVENT+1,
  173.     T_DNRADDRTONAMECOMPLETE        = kPRIVATEEVENT+2,
  174.     T_DNRSYSINFOCOMPLETE        = kPRIVATEEVENT+3,
  175.     T_DNRMAILEXCHANGECOMPLETE    = kPRIVATEEVENT+4,
  176.     T_DNRQUERYCOMPLETE            = kPRIVATEEVENT+5
  177. };
  178.  
  179. /*******************************************************************************
  180. ** InetAddress
  181. ********************************************************************************/
  182.  
  183. struct InetAddress
  184. {
  185.         OTAddressType    fAddressType;    // always AF_INET
  186.         InetPort        fPort;            // Port number 
  187.         InetHost        fHost;            // Host address in net byte order
  188.         UInt8            fUnused[8];        // Traditional unused bytes
  189. };
  190. typedef struct InetAddress InetAddress;
  191.  
  192. /*******************************************************************************
  193. ** Domain Name Resolver (DNR) 
  194. ********************************************************************************/
  195.  
  196. enum 
  197.         kMaxHostAddrs         =  10,
  198.         kMaxSysStringLen     =  32,
  199.         kMaxHostNameLen        = 255
  200. };
  201.  
  202. typedef char InetDomainName[kMaxHostNameLen + 1];
  203.  
  204. struct InetHostInfo
  205. {
  206.     InetDomainName    name;
  207.     InetHost        addrs[kMaxHostAddrs];
  208. };
  209. typedef struct InetHostInfo    InetHostInfo;
  210.  
  211. struct InetSysInfo
  212. {
  213.     char        cpuType[kMaxSysStringLen];
  214.     char        osType[kMaxSysStringLen];
  215. };
  216. typedef struct InetSysInfo InetSysInfo;
  217.  
  218. struct InetMailExchange
  219. {
  220.     UInt16            preference;
  221.     InetDomainName    exchange;
  222. };
  223. typedef struct InetMailExchange InetMailExchange;
  224.  
  225. struct DNSQueryInfo
  226. {
  227.     UInt16            qType;
  228.     UInt16            qClass;
  229.     UInt32            ttl;
  230.     InetDomainName    name;
  231.     UInt16            responseType;        // answer, authority, or additional
  232.     UInt16            resourceLen;        // actual length of array which follows
  233.     char            resourceData[4];    // size varies
  234. };
  235. typedef struct DNSQueryInfo DNSQueryInfo;
  236.  
  237.  
  238. /*******************************************************************************
  239. ** DNSAddress
  240. **
  241. **        The DNSAddress format is optional and may be used in connects,
  242. **        datagram sends, and resolve address calls.   The name takes the 
  243. **        format "somewhere.com" or "somewhere.com:portnumber" where
  244. **        the ":portnumber" is optional.   The length of this structure
  245. **        is arbitrarily limited to the overall max length of a domain
  246. **        name (255 chars), although a longer one can be use successfully
  247. **        if you use this as a template for doing so.   However, the domain name 
  248. **        is still limited to 255 characters.
  249. ********************************************************************************/
  250.  
  251. struct DNSAddress
  252. {
  253.     OTAddressType    fAddressType;    // always AF_DNS
  254.     InetDomainName    fName;            
  255. };
  256. typedef struct DNSAddress DNSAddress;
  257.  
  258. /*******************************************************************************
  259. ** InetInterfaceInfo
  260. ********************************************************************************/
  261.  
  262. struct InetInterfaceInfo
  263. {
  264.     InetHost        fAddress;
  265.     InetHost        fNetmask;
  266.     InetHost        fBroadcastAddr;
  267.     InetHost        fDefaultGatewayAddr;
  268.     InetHost        fDNSAddr;
  269.     UInt16            fVersion;
  270.     UInt16            fHWAddrLen;
  271.     UInt8*            fHWAddr;
  272.     UInt32            fIfMTU;
  273.     UInt8*            fReservedPtrs[2];
  274.     InetDomainName    fDomainName;
  275.     UInt32            fIPSecondaryCount;
  276.     UInt8            fReserved[252];            
  277. };
  278. typedef struct InetInterfaceInfo InetInterfaceInfo;
  279.  
  280.  
  281.  
  282. /*******************************************************************************
  283. ** Static helper functions
  284. ********************************************************************************/
  285.  
  286. #ifdef __cplusplus
  287. extern "C" {
  288. #endif
  289.  
  290. extern pascal void             OTInitInetAddress(InetAddress* addr, InetPort port, InetHost host);
  291. extern pascal size_t        OTInitDNSAddress(DNSAddress* addr, char* str);
  292. extern pascal OSStatus         OTInetStringToHost(char* str, InetHost* host);
  293. extern pascal void          OTInetHostToString(InetHost host, char* str);
  294. extern pascal OSStatus         OTInetGetInterfaceInfo(InetInterfaceInfo* info, SInt32 val);
  295. extern pascal OSStatus         OTInetGetSecondaryAddresses(InetHost* addr, UInt32* count, SInt32 val);
  296.  
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300.  
  301.  
  302. /*******************************************************************************
  303. ** InetServices & DNR calls
  304. ********************************************************************************/
  305.  
  306. #define kDefaultInternetServicesPath    ((OTConfiguration*)-3)
  307.  
  308. #if !OTKERNEL
  309.  
  310. #ifdef __cplusplus
  311. extern "C" {
  312. #endif
  313.  
  314. extern pascal InetSvcRef     OTOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, OSStatus* err);
  315. extern pascal OSStatus        OTAsyncOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, 
  316.                                                         OTNotifyProcPtr proc, void* contextPtr);
  317. extern pascal OSStatus         OTInetStringToAddress(InetSvcRef ref, char* name,
  318.                                                   InetHostInfo* hinfo);
  319. extern pascal OSStatus         OTInetAddressToName(InetSvcRef ref, InetHost addr, 
  320.                                                 InetDomainName name);
  321. extern pascal OSStatus         OTInetSysInfo(InetSvcRef ref, char* name,
  322.                                           InetSysInfo* sysinfo);
  323. extern pascal OSStatus         OTInetMailExchange(InetSvcRef ref, char* name, UInt16* num,
  324.                                                InetMailExchange* mx);
  325.                                                
  326. extern pascal OSStatus        OTInetQuery(InetSvcRef ref, char* name, UInt16 qClass, UInt16 qType,
  327.                                           char* buf, size_t buflen, 
  328.                                         void** argv, size_t argvlen,
  329.                                         OTFlags flags);
  330.                     
  331.  
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335.  
  336. enum
  337. {
  338.     kDefaultInetInterface    = -1,
  339.     kInetInterfaceInfoVersion    = 3
  340. };
  341.  
  342. #ifdef __cplusplus
  343.  
  344. class TInternetServices : public TProvider
  345. {
  346.     public:
  347.             OSStatus     StringToAddress(char* name, InetHostInfo* hinfo)
  348.                         { return OTInetStringToAddress(this, name, hinfo); }
  349.                     
  350.             OSStatus     AddressToName(InetHost addr, InetDomainName name)
  351.                         { return OTInetAddressToName(this, addr, name); }
  352.                     
  353.             OSStatus     SysInfo(char* name, InetSysInfo* sysinfo )
  354.                         { return OTInetSysInfo(this, name, sysinfo); }
  355.                     
  356.             OSStatus     MailExchange(char* name, UInt16* num, InetMailExchange* mx)
  357.                         { return OTInetMailExchange(this, name, num, mx); }
  358.                         
  359.             OSStatus    Query(char* name, UInt16 qClass, UInt16 qType, 
  360.                               char* buf, size_t buflen, 
  361.                               void** argv, size_t argvlen,
  362.                               OTFlags flags)
  363.                         { return OTInetQuery(this, name, qClass, qType, buf, buflen, argv, argvlen, flags); }
  364. };
  365.  
  366. #endif
  367. #endif        /* !OTKERNEL */
  368.  
  369. #if PRAGMA_ALIGN_SUPPORTED
  370. #pragma options align=reset
  371. #endif
  372. #if PRAGMA_IMPORT_SUPPORTED
  373. #pragma import off
  374. #endif
  375.  
  376. #endif    /* __OTINTERNET__ */
  377.